Skip to content

Use mockedObject for TreeView#2768

Merged
robertbrignull merged 1 commit intomainfrom
robertbrignull/mocked-treeview
Sep 1, 2023
Merged

Use mockedObject for TreeView#2768
robertbrignull merged 1 commit intomainfrom
robertbrignull/mocked-treeview

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

This is one possible solution to the conversation from https://github.com/github/vscode-codeql/pull/2735/files#r1303916205.

Effectively this is still using as unknown as X but at least that's now contained within mockedObject which mocks all other fields and methods and throws a helpful error message when code tries to use them.

I think using mockedObject for the TreeView type makes sense. It's a hard type to provide a "real" instance of, because:

  • It's not a type we own or control.
  • It's quite a large type with lots of methods we often don't care about.
  • It's an interface that "does stuff" rather than being a data type that just contains static data.

Also importantly, we don't ever do type checking on this type, so fields being mocked doesn't cause problems with this. In the linked PR I objected to using mockedObject for the ExternalApiUsage and Usage types because we have the isExternalApiUsage method and therefore the actual fields at runtime matter and not just appeasing the typescript type system.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@robertbrignull robertbrignull requested a review from a team as a code owner August 31, 2023 11:12
Copy link
Copy Markdown
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think this is an improvement so we should go ahead with it.

I also think that it's not out of the question to provide some functions to mock TreeView objects if we wanted to, but that's something for another day.

@robertbrignull robertbrignull merged commit 1861692 into main Sep 1, 2023
@robertbrignull robertbrignull deleted the robertbrignull/mocked-treeview branch September 1, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants